<template>
  <div class="payMethods front-color">
    <template v-if="defaultPage">
      <div class="pageDes front-color">
        <h1>{{$t('myAdd.payAndCollset.payMethods')}}</h1>
        <p>{{$t('myAdd.payAndCollset.payMethodsDes')}}</p>
      </div>
      <div class="interlaced"></div>
      <div class="methods front-color">
        <div class="method alipay">
          <div class="name alipay_name">
            <span class="name_text">{{Internationalization.alipay}}</span>
          </div>
          <div class="info alipay_info">
            <span class="info_text" v-if="!myData.alipay.accountName">{{Internationalization.notSet}}</span>
            <span class="info_acc" v-else>{{myData.alipay.accountName}}</span>
            <button v-if="!myData.alipay.accountName" @click="toPayAndCollSet('alipay')">{{Internationalization.setting}}</button>
            <button v-else class="cancel" @click="toPayAndCollSet('alipay')">{{Internationalization.changeSet}}</button>
          </div>
        </div>
        <div class="method wechat">
          <div class="name wechat_name">
            <span class="name_text">{{Internationalization.wechatPay}}</span>
          </div>
          <div class="info wechat_info">
            <span class="info_text" v-if="!myData.wechat.accountName">{{Internationalization.notSet}}</span>
            <span class="info_acc" v-else>{{myData.wechat.accountName}}</span>
            <button v-if="!myData.wechat.accountName" @click="toPayAndCollSet('wechat')">{{Internationalization.setting}}</button>
            <button v-else class="cancel" @click="toPayAndCollSet('wechat')">{{Internationalization.changeSet}}</button>
          </div>
        </div>
        <div class="method bank">
          <div class="name bank_name">
            <span class="name_text">{{Internationalization.bankTransfer}}</span>
          </div>
          <div class="info bank_info">
            <span class="info_text" v-if="!myData.bank.bankName">{{Internationalization.notSet}}</span>
            <span class="info_acc" v-else>{{myData.bank.bankAcc}}</span>
            <button v-if="!myData.bank.bankName" @click="toPayAndCollSet('bank')">{{Internationalization.setting}}</button>
            <button v-else class="cancel" @click="toPayAndCollSet('bank')">{{Internationalization.changeSet}}</button>
          </div>
        </div>
      </div>
    </template>
    <template v-if="!defaultPage && alipayPage">
      <div class="front-color bindAlipay">
        <div class="bind clearfix">
          <span class="title">{{$t('myAdd.payAndCollset.bindAliPay')}}</span>
          <span class="back pointer" @click="goBack">< {{$t('myAdd.payAndCollset.back')}}</span>
        </div>
        <div class="operate">
          <ul>
            <li>
              <div class="inputDiv">
                <inline-input
                  v-bind:title="Internationalization.getMoneyName"
                  v-bind:property = "formData.aplayName"
                  v-model = "formData.aplayName.value"
                  v-on:onevents = "somethings"
                >
                </inline-input>
              </div>
              <errorTip  v-show="formData.aplayName.errorTip" :info="formData.aplayName.errorTip"></errorTip>
            </li>
            <li>
              <div class="inputDiv">
                <inline-input
                  v-bind:property = "formData.aplayAcc"
                  v-model = "formData.aplayAcc.value"
                  v-on:onevents = "somethings"
                >
                </inline-input>
              </div>
              <errorTip  v-show="formData.aplayAcc.errorTip" :info="formData.aplayAcc.errorTip"></errorTip>
            </li>
            <li class="clearfix uploadLi">
              <uploadImg @onevents="alipayImgUrl" :showImg = 'alipayShowImg'></uploadImg>
              <label>{{Internationalization.uploadCollCode}}</label>
            </li>
            <template v-for="(item, key, index) in formListAlipay">
              <li>
                <inline-input
                  v-bind:property = "item"
                  v-model = "item.value"
                  v-on:onevents = "somethingsAlipay">
                </inline-input>
              </li>
            </template>
          </ul>
          <div class="btn">
            <button @click="setAlipayBtn" :class="{readOnly: !secondClick}">{{$t('myAdd.payAndCollset.sure')}}</button>
          </div>
        </div>
      </div>
    </template>
    <template v-if="!defaultPage && wechatPage">
      <div class="front-color bindWeChat">
        <div class="bind clearfix">
          <span class="title">{{$t('myAdd.payAndCollset.bindWechat')}}</span>
          <span class="back pointer" @click="goBack">< {{$t('myAdd.payAndCollset.back')}}</span>
        </div>
        <div class="operate">
          <ul>
            <li>
              <div class="inputDiv">
                <inline-input
                  v-bind:property = "formData.wechatName"
                  v-model = "formData.wechatName.value"
                  v-on:onevents = "somethings"
                >
                </inline-input>
              </div>
              <errorTip  v-show="formData.wechatName.errorTip" :info="formData.wechatName.errorTip"></errorTip>
            </li>
            <li>
              <div class="inputDiv">
                <inline-input
                  v-bind:property = "formData.wechatAcc"
                  v-model = "formData.wechatAcc.value"
                  v-on:onevents = "somethings"
                >
                </inline-input>
                <errorTip  v-show="formData.wechatAcc.errorTip" :info="formData.wechatAcc.errorTip"></errorTip>
              </div>
            </li>
            <li class="clearfix uploadLi">
              <uploadImg @onevents="wechatImgUrl" :showImg = 'wechatShowImg'></uploadImg>
              <label>{{Internationalization.uploadCollCode}}</label>
            </li>
            <template v-for="(item, key, index) in formListWechat">
              <li>
                <inline-input
                  v-bind:property = "item"
                  v-model = "item.value"
                  v-on:onevents = "somethingsWechat">
                </inline-input>
              </li>
            </template>
          </ul>
          <div class="btn">
            <button @click="setWechatBtn" :class="{readOnly: !secondClick}">{{$t('myAdd.payAndCollset.sure')}}</button>
          </div>
        </div>
      </div>
    </template>
    <template v-if="!defaultPage && bankPage">
      <div class="front-color bindBank">
        <div class="bind clearfix">
          <span class="title">{{$t('myAdd.payAndCollset.bindBank')}}</span>
          <span class="back pointer" @click="goBack">< {{$t('myAdd.payAndCollset.back')}}</span>
        </div>
        <div class="operate">
          <ul>
            <li>
              <div class="inputDiv">
                <inline-input
                  v-bind:property = "formData.bankAccName"
                  v-model = "formData.bankAccName.value"
                  v-on:onevents = "somethings"
                >
                </inline-input>
              </div>
              <errorTip  v-show="formData.bankAccName.errorTip" :info="formData.bankAccName.errorTip"></errorTip>
            </li>
            <li>
              <div class="inputDiv">
                <inline-input
                  v-bind:property = "formData.bankName"
                  v-model = "formData.bankName.value"
                  v-on:onevents = "somethings"
                >
                </inline-input>
              </div>
              <errorTip  v-show="formData.bankName.errorTip" :info="formData.bankName.errorTip"></errorTip>
            </li>
            <li>
              <div class="inputDiv">
                <inline-input
                  v-bind:property = "formData.bankSubName"
                  v-model = "formData.bankSubName.value"
                  v-on:onevents = "somethings"
                >
                </inline-input>
              </div>
              <errorTip  v-show="formData.bankSubName.errorTip" :info="formData.bankSubName.errorTip"></errorTip>
            </li>
            <li>
              <div class="inputDiv">
                <inline-input
                  v-bind:property = "formData.bankAcc"
                  v-model = "formData.bankAcc.value"
                  v-on:onevents = "somethings"
                >
                </inline-input>
              </div>
              <errorTip  v-show="formData.bankAcc.errorTip" :info="formData.bankAcc.errorTip"></errorTip>
            </li>
            <li>
              <div class="inputDiv">
                <inline-input
                  v-bind:property = "formData.confirmBankAcc"
                  v-model = "formData.confirmBankAcc.value"
                  v-on:onevents = "somethings"
                >
                </inline-input>
              </div>
              <errorTip  v-show="formData.confirmBankAcc.errorTip" :info="formData.confirmBankAcc.errorTip"></errorTip>
            </li>
            <template v-for="(item, key, index) in formListBank">
              <li>
                <inline-input
                  v-bind:property = "item"
                  v-model = "item.value"
                  v-on:onevents = "somethingsBank">
                </inline-input>
              </li>
            </template>
          </ul>
          <div class="btn">
            <button @click="setBankBtn" :class="{readOnly: !secondClick}">{{$t('myAdd.payAndCollset.sure')}}</button>
          </div>
        </div>
      </div>
    </template>
    <!-- 实名认证弹窗 -->
    <el-dialog
      title=''
      :flag='toC1Verify'
      name= 'toC1Verify'
      :width='450'
      :dialogClose='closeDialog'>
      <div class="mobileverify-text" slot="content">{{Internationalization.c1verify}}</div>
      <div class="toCiVerifyFooter" slot="options">
        <button @click="closeDialog" class="cancel">{{Internationalization.cancel}}</button>
        <router-link tag="button" to="/personal/information">{{Internationalization.goRealname}}</router-link>
      </div>
    </el-dialog >
    <!-- 谷歌或手机验证弹窗 -->
    <el-dialog
      title=''
      :flag='googleOrMobelVerty'
      name= 'googleOrMobelVerty'
      :width='450'
      :dialogClose='closeDialog'>
      <div class="mobileverify-text" slot="content">{{Internationalization.needVerify}}</div>
      <div class="googleOrMobelVertyFooter" slot="options">
        <button @click="closeDialog" class="cancel">{{Internationalization.cancel}}</button>
        <router-link tag="button" to="/personal/securityCenter">{{Internationalization.setSafety}}</router-link>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import InlineInput from '@/components/common/inlineInput'
import uploadImg from '@/components/addPage/common/upload'
import errorTip from '@/components/addPage/common/errorTipP'
import elDialog from '@/components/common/addCommon/dialog'

export default {
  name: 'payMethod',
  components: { InlineInput, uploadImg, errorTip, elDialog },
  data () {
    return {
      defaultPage: true,
      alipayPage: false,
      wechatPage: false,
      bankPage: false,
      wechatShowImg: null,
      alipayShowImg: null,
      formListBank: {},
      formListWechat: {},
      formListAlipay: {},
      formData: {},
      myData: {
        bank: {
          'payment': 'otc.payment.international.wire.transfer',
          'bankAccName': null,
          'bankAcc': null,
          'bankName': null,
          'bankSubName': null,
          'smsValidCode': null,
          'googleCode': null
        },
        wechat: {
          'payment': 'otc.payment.wxpay',
          'imgUrl': null,
          // 'imgUrl': 'https://www.yex.com/upload/images/201808311918036_7e9VI.jpg',
          'accountName': null,
          'account': null,
          'smsValidCode': null,
          'googleCode': null
        },
        alipay: {
          'payment': 'otc.payment.alipay',
          'imgUrl': null,
          // 'imgUrl': 'https://www.yex.com/upload/images/201808031007032_11FMW.jpg',
          'accountName': null,
          'account': null,
          'smsValidCode': null,
          'googleCode': null
        }
      },
      secondClick: true,
      toC1Verify: false,
      googleOrMobelVerty: false,
      pat: new RegExp('[^a-zA-Z0-9_\u4e00-\u9fa5]', 'i') // 检测非法字符
    }
  },
  created () {
    this.formListBank = this._P.copyObject(this.formList_obj, true)
    this.formListWechat = this._P.copyObject(this.formList_obj, true)
    this.formListAlipay = this._P.copyObject(this.formList_obj, true)
    this.formData = this.formData_obj
  },
  computed: {
    ...mapState({
      userinfo ({baseData: {_user}}) {
        return _user || false
      }
    }),
    Internationalization () {
      return {
        peopleName: this.$t('myAdd.payAndCollset.peopleName'), // 输入昵称
        inputAlipay: this.$t('myAdd.payAndCollset.inputAlipay'), // 请输入支付宝账号
        inputWeChat: this.$t('myAdd.payAndCollset.inputWeChat'), // 请输入微信号
        inputInter: this.$t('myAdd.payAndCollset.inputInter'), // 请输入国际电汇
        inputAccount: this.$t('myAdd.payAndCollset.inputAccount'), // 请输入账户名
        inputBankName: this.$t('myAdd.payAndCollset.inputBankName'), // 请输入银行名称
        inputBankSub: this.$t('myAdd.payAndCollset.inputBankSub'), // 请输入开户行
        inputAccNumber: this.$t('myAdd.payAndCollset.inputAccNumber'), // 请输入账号
        confirmBankAcc: this.$t('myAdd.payAndCollset.confirmBankAcc'), // 请再次输入卡号
        firstGoRealname: this.$t('myAdd.payAndCollset.firstGoRealname'), // 请先进行实名验证
        goRealname: this.$t('myAdd.payAndCollset.goRealname'), // 去实名
        needVerify: this.$t('myAdd.payAndCollset.needVerify'), // 手机谷歌验证至少需要一个
        setSafety: this.$t('myAdd.payAndCollset.setSafety'), // 去验证
        smsAuthCode: this.$t('myAdd.payAndCollset.smsAuthCode'), // 手机验证码
        googleCode: this.$t('myAdd.payAndCollset.googleCode'), // 谷歌验证码
        passCode: this.$t('myAdd.payAndCollset.passCode'), // 验证码已发送
        payAndCollset: this.$t('myAdd.payAndCollset.payAndCollset'), // 收付款设置
        bankTransfer: this.$t('myAdd.payAndCollset.bankTransfer'), // 银行转账
        setting: this.$t('myAdd.payAndCollset.set'), // 绑定
        changeSet: this.$t('myAdd.payAndCollset.edit'), // 修改
        notSet: this.$t('myAdd.payAndCollset.notSet'), // 未绑定
        theName: this.$t('myAdd.payAndCollset.theName'), // 姓名
        openBank: this.$t('myAdd.payAndCollset.openBank'), // 开户行
        openMasterBank: this.$t('myAdd.payAndCollset.openMasterBank'), // 开户支行
        bankAcc: this.$t('myAdd.payAndCollset.bankAcc'), // 银行卡号
        comfirmBankAcc: this.$t('myAdd.payAndCollset.comfirmBankAcc'), // 确认卡号
        wechatPay: this.$t('myAdd.payAndCollset.wechatPay'), // 微信支付
        account: this.$t('myAdd.payAndCollset.account'), // 账号
        getMoneyName: this.$t('myAdd.payAndCollset.getMoneyName'), // 收款人姓名
        uploadCollCode: this.$t('myAdd.payAndCollset.uploadCollCode'), // 上传收款码
        alipay: this.$t('myAdd.payAndCollset.alipay'), // 支付宝支付
        nameErrorTip: this.$t('myAdd.payAndCollset.nameErrorTip'), // 请输入至少为两位的中文汉字
        nameErrorTip1: this.$t('myAdd.payAndCollset.nameErrorTip1'), // 请输入至少为四位的中文汉字
        openMasterBankErrorTip: this.$t('myAdd.payAndCollset.openMasterBankErrorTip'), // 请输入正确的开户支行
        enterRightBankAcc: this.$t('myAdd.payAndCollset.enterRightBankAcc'), // 请输入正确的银行卡号
        enterSameBankAcc: this.$t('myAdd.payAndCollset.enterSameBankAcc'), // 请输入相同的银行卡号
        firstEnterBankAcc: this.$t('myAdd.payAndCollset.firstEnterBankAcc'), // 请先输入卡号
        pleaseEnterOpenMasterBank: this.$t('myAdd.payAndCollset.pleaseEnterOpenMasterBank'), // 请输入开户支行
        pleaseEnterBankAcc: this.$t('myAdd.payAndCollset.pleaseEnterBankAcc'), // 请输入银行卡号
        VerificationNotRight: this.$t('myAdd.payAndCollset.VerificationNotRight'), // 验证码输入不正确
        pleaseConfirmBankAcc: this.$t('myAdd.payAndCollset.pleaseConfirmBankAcc'), // 请确认卡号
        pleaseCheck: this.$t('myAdd.payAndCollset.pleaseCheck'), // 请检查
        pleaseUploadCollCode: this.$t('myAdd.payAndCollset.pleaseUploadCollCode'), // 请上传收款码
        c1verify: this.$t('myAdd.payAndCollset.c1verify'), // c1认证
        cancel: this.$t('myAdd.payAndCollset.cancel'), // 取消
        nameErrorTip2: this.$t('myAdd.payAndCollset.nameErrorTip2') // 不能含有特殊字符
      }
    },
    formList_obj () {
      let obj = {}
      if (this.userinfo.googleStatus === 1) {
        Object.assign(obj, {
          googleCode: {
            title: this.Internationalization.googleCode,
            placeholder: this.Internationalization.googleCode,
            formType: 'text',
            type: null,
            name: 'googleCode',
            value: ''
          }
        })
      } else if (this.userinfo.isOpenMobileCheck === 1) {
        Object.assign(obj, {
          smsValidCode: {
            title: this.Internationalization.smsAuthCode,
            placeholder: this.Internationalization.smsAuthCode,
            formType: 'verifiCode',
            name: 'smsValidCode',
            operationType: 51,
            startTime: false,
            data: [],
            value: ''
          }
        })
      }
      return obj
    },
    // 收款账号组件
    formData_obj () {
      return {
        aplayAcc: { // 支付宝账号
          title: this.Internationalization.account,
          placeholder: this.Internationalization.inputAlipay,
          formType: 'text',
          name: 'aplayAcc',
          value: ''
        },
        aplayName: { // 支付宝账户名
          title: this.Internationalization.getMoneyName,
          placeholder: this.Internationalization.inputAccount,
          formType: 'text',
          name: 'aplayName',
          value: '',
          errorTip: null
        },
        wechatAcc: { // 微信账号
          title: this.Internationalization.account,
          placeholder: this.Internationalization.inputWeChat,
          formType: 'text',
          name: 'wechatAcc',
          value: ''
        },
        wechatName: { // 微信账户名
          title: this.Internationalization.getMoneyName,
          placeholder: this.Internationalization.inputAccount,
          formType: 'text',
          name: 'wechatName',
          value: '',
          errorTip: null
        },
        bankAcc: { // 银行卡账号
          title: this.Internationalization.bankAcc,
          placeholder: this.Internationalization.inputInter,
          formType: 'number',
          name: 'bankAcc',
          value: '',
          errorTip: null
        },
        bankAccName: { // 银行卡账户名
          title: this.Internationalization.theName,
          placeholder: this.Internationalization.inputAccount,
          formType: 'text',
          name: 'bankAccName',
          value: '',
          errorTip: null
        },
        bankName: {  // 输入银行名称
          placeholder: this.Internationalization.inputBankName,
          name: 'bankName',
          value: '',
          title: this.Internationalization.openBank,
          formType: 'text',
          errorTip: null
        },
        bankSubName: { // 开户支行
          title: this.Internationalization.openMasterBank,
          placeholder: this.Internationalization.inputBankSub,
          formType: 'text',
          name: 'bankSubName',
          value: '',
          errorTip: null
        },
        confirmBankAcc: { // 确认卡号
          title: this.Internationalization.comfirmBankAcc,
          placeholder: this.Internationalization.confirmBankAcc,
          formType: 'number',
          name: 'confirmBankAcc',
          value: '',
          errorTip: null
        }
      }
    }
  },
  methods: {
    // 收付款数据
    paymentsData () {
      this.axios({
        method: 'post',
        url: this.$store.state.otcUrl.receiving.getPayment,
        params: {},
        hostType: 'otc'
      }).then(res => {
        if (res.code.toString() === '0') {
          res = res.data
          res.forEach((item, index) => {
            switch (item.payment) {
              case 'otc.payment.international.wire.transfer':
                if (this.userinfo.isOpenMobileCheck === 1 && this.userinfo.googleStatus !== 1) {
                  this.formListBank.smsValidCode.operationType = 52  // 修改收付款信息是52
                  localStorage.setItem('operationTypeBank', 'true')
                }
                this.formData.bankAccName.value = item.bankAccName
                this.formData.bankName.value = item.bankName
                this.formData.bankSubName.value = item.bankSubName
                this.formData.bankAcc.value = item.bankAcc
                this.myData.bank.bankAccName = item.bankAccName
                this.myData.bank.bankName = item.bankName
                this.myData.bank.bankSubName = item.bankSubName
                this.myData.bank.bankAcc = item.bankAcc
                break
              case 'otc.payment.wxpay':
                if (this.userinfo.isOpenMobileCheck === 1 && this.userinfo.googleStatus !== 1) {
                  this.formListWechat.smsValidCode.operationType = 52  // 修改收付款信息是52
                  localStorage.setItem('operationTypeWechat', 'true')
                }
                this.formData.wechatName.value = item.accountName
                this.formData.wechatAcc.value = item.account
                this.myData.wechat.imgUrl = item.imgurl
                this.myData.wechat.accountName = item.accountName
                this.myData.wechat.account = item.account
                this.wechatShowImg = item.imgurl
                break
              case 'otc.payment.alipay':
                if (this.userinfo.isOpenMobileCheck === 1 && this.userinfo.googleStatus !== 1) {
                  this.formListAlipay.smsValidCode.operationType = 52  // 修改收付款信息是52
                  localStorage.setItem('operationTypeAlipay', 'true')
                }
                this.formData.aplayAcc.value = item.account
                this.formData.aplayName.value = item.accountName
                this.myData.alipay.imgUrl = item.imgurl
                this.myData.alipay.accountName = item.accountName
                this.myData.alipay.account = item.account
                this.alipayShowImg = item.imgurl
                break
            }
          })
        } else {
          this.$store.dispatch('setTipState', { text: res.msg, type: 'error' })
        }
      })
    },
    // 银行数据
    bankData () {
      this.axios({
        method: 'post',
        url: this.$store.state.otcUrl.receiving.bankInfo,
        params: {},
        hostType: 'otc'
      }).then((res) => {
        const _self = this
        if (res.code.toString() === '0') {
          res = res.data.banklist
          res.forEach((item, index) => {
            let obj = {}
            obj.value = item.bankname
            obj.code = item.bankname
            _self.formData_obj.bankName.optionList.push(obj)
          })
        }
      })
    },
    somethings (val) {
      if (val.name === 'bankAccName') { // 银行户名
        if (val.value.trim().length > 0) {
          if (val.value.trim().length < 2) {
            this.formData.bankAccName.errorTip = this.Internationalization.nameErrorTip
          } else if (val.value.trim().length >= 2) {
            if (this.pat.test(val.value.trim())) {
              this.formData.bankAccName.errorTip = this.Internationalization.nameErrorTip2
            } else {
              this.formData.bankAccName.errorTip = null
            }
          }
          this.myData.bank.bankAccName = val.value.trim()
        } else {
          this.myData.bank.bankAccName = null
        }
      }
      if (val.name === 'bankName') { // 银行名字
        if (val.value.trim().length > 0) {
          if (val.value.trim().length < 4) {
            this.formData.bankName.errorTip = this.Internationalization.nameErrorTip1
          } else if (val.value.trim().length >= 4) {
            if (this.pat.test(val.value.trim())) {
              this.formData.bankName.errorTip = this.Internationalization.nameErrorTip2
            } else {
              this.formData.bankName.errorTip = null
            }
          }
          this.myData.bank.bankName = val.value.trim()
        } else {
          this.myData.bank.bankName = null
        }
      }
      if (val.name === 'bankSubName') { // 支行名字
        if (val.value.trim().length > 0) {
          if (val.value.trim().length < 4) {
            this.formData.bankSubName.errorTip = this.Internationalization.openMasterBankErrorTip
          } else if (val.value.trim().length >= 4) {
            if (this.pat.test(val.value.trim())) {
              this.formData.bankSubName.errorTip = this.Internationalization.openMasterBankErrorTip
            } else {
              this.formData.bankSubName.errorTip = null
            }
          }
          this.myData.bank.bankSubName = val.value.trim()
        } else {
          this.myData.bank.bankSubName = null
        }
      }
      if (val.name === 'bankAcc') { // 银行卡卡号
        if (val.value.length >= 16 && val.value.length <= 19) {
          this.myData.bank.bankAcc = val.value
          this.formData.bankAcc.errorTip = null
        } else if (val.value.length === 0) {
          this.formData.bankAcc.errorTip = this.Internationalization.enterRightBankAcc
          this.myData.bank.bankAcc = null
        } else {
          this.myData.bank.bankAcc = val.value
          this.formData.bankAcc.errorTip = this.Internationalization.enterRightBankAcc
        }
      }
      if (val.name === 'confirmBankAcc') { // 确认卡号
        if (val.value.length > 0 && this.myData.bank.bankAcc !== null && this.myData.bank.bankAcc.length > 0 && this.formData.bankAcc.errorTip === null) {
          if (val.value !== this.myData.bank.bankAcc) {
            this.formData.confirmBankAcc.errorTip = this.Internationalization.enterSameBankAcc
          } else {
            this.formData.confirmBankAcc.errorTip = null
          }
        }
        if (val.value > 0 && this.myData.bank.bankAcc === null) {
          this.formData.confirmBankAcc.errorTip = this.Internationalization.firstEnterBankAcc
        }
      }
      if (val.name === 'wechatName') { // 微信账户名
        if (val.value.trim().length > 0) {
          if (val.value.trim().length < 2) {
            this.formData.wechatName.errorTip = this.Internationalization.nameErrorTip
          } else if (val.value.trim().length >= 2) {
            if (this.pat.test(val.value.trim())) {
              this.formData.wechatName.errorTip = this.Internationalization.nameErrorTip2
            } else {
              this.formData.wechatName.errorTip = null
            }
          }
          this.myData.wechat.accountName = val.value.trim()
        } else {
          this.myData.wechat.accountName = null
        }
      }
      if (val.name === 'wechatAcc') { // 微信账号
        if (val.value.length > 0) {
          this.myData.wechat.account = val.value
        } else {
          this.myData.wechat.account = null
        }
      }
      if (val.name === 'aplayName') { // 支付宝账户名
        if (val.value.trim().length > 0) {
          if (val.value.trim().length < 2) {
            this.formData.aplayName.errorTip = this.Internationalization.nameErrorTip
          } else if (val.value.trim().length >= 2) {
            if (this.pat.test(val.value.trim())) {
              this.formData.aplayName.errorTip = this.Internationalization.nameErrorTip2
            } else {
              this.formData.aplayName.errorTip = null
            }
          }
          this.myData.alipay.accountName = val.value.trim()
        } else {
          this.myData.bank.accountName = null
        }
      }
      if (val.name === 'aplayAcc') { // 支付宝账号
        if (val.value.length > 0) {
          this.myData.alipay.account = val.value
        } else {
          this.myData.alipay.account = null
        }
      }
    },
    somethingsBank (val) {
      if (val.handleType === 'sendCode') { // 短信验证码
        if (localStorage.getItem('operationTypeBank') === 'true') {
          this.formListBank.smsValidCode.operationType = 52
        }
        this.sendCode(val, this.formListBank)
      }
    },
    somethingsWechat (val) {
      if (val.handleType === 'sendCode') { // 短信验证码
        if (localStorage.getItem('operationTypeWechat') === 'true') {
          this.formListWechat.smsValidCode.operationType = 52
        }
        this.sendCode(val, this.formListWechat)
      }
    },
    somethingsAlipay (val) {
      if (val.handleType === 'sendCode') { // 短信验证码
        if (localStorage.getItem('operationTypeAlipay') === 'true') {
          this.formListAlipay.smsValidCode.operationType = 52
        }
        this.sendCode(val, this.formListAlipay)
      }
    },
    sendCode (item, payType) { // 发送验证码
      let data = {}
      if (payType[item.name].startTime) return false
      data.operationType = payType[item.name].operationType
      payType[item.name].startTime = true // 开启倒计时
      this.commonHttp.smsValidCode(data).then((data) => {
        if (data.code === '0') {
          this.$store.dispatch('setTipState', this.Internationalization.passCode)
        } else {
          payType.smsValidCode.startTime = false  // 关闭倒计时
          this.$store.dispatch('setTipState', {text: data.msg, type: 'error'})
        }
      })
    },
    setBankBtn () { // 取消和确认
      if (this.userinfo.isOpenMobileCheck === 1 && this.userinfo.googleStatus !== 1) {
        this.myData.bank.smsValidCode = this.formListBank.smsValidCode.value
      } else if (this.userinfo.googleStatus === 1) {
        this.myData.bank.googleCode = this.formListBank.googleCode.value
      }
      for (let k in this.myData.bank) {
        if (k === 'bankAccName' && this.myData.bank[k] === null) {
          this.$store.dispatch('setTipState', {text: this.Internationalization.inputAccount, type: 'error'})
          return false
        }
        if (k === 'bankName' && this.myData.bank[k] === null) {
          this.$store.dispatch('setTipState', {text: this.Internationalization.inputBankSub, type: 'error'})
          return false
        }
        if (k === 'bankSubName' && this.myData.bank[k] === null) {
          this.$store.dispatch('setTipState', {text: this.Internationalization.pleaseEnterOpenMasterBank, type: 'error'})
          return false
        }
        if (k === 'bankAcc' && this.myData.bank[k] === null) {
          this.$store.dispatch('setTipState', {text: this.Internationalization.pleaseEnterBankAcc, type: 'error'})
          return false
        }
        if (k === 'smsValidCode' && this.userinfo.googleStatus !== 1 && this.userinfo.isOpenMobileCheck === 1) { // 短信验证码
          if (this.myData.bank.smsValidCode.length !== 6) {
            this.$store.dispatch('setTipState', {text: this.Internationalization.VerificationNotRight, type: 'error'})
            return false
          }
        }
        if (k === 'googleCode' && this.userinfo.googleStatus === 1) {
          if (this.myData.bank.googleCode.length !== 6) {
            this.$store.dispatch('setTipState', {text: this.Internationalization.VerificationNotRight, type: 'error'})
            return false
          }
        }
      }
      if (this.formData.confirmBankAcc.value.length === 0) {
        this.$store.dispatch('setTipState', {text: this.Internationalization.pleaseConfirmBankAcc, type: 'error'})
        return false
      }
      if (this.formData.bankAccName.errorTip !== null || this.formData.bankSubName.errorTip !== null || this.formData.bankAcc.errorTip !== null || this.formData.confirmBankAcc.errorTip) {
        this.$store.dispatch('setTipState', {text: this.Internationalization.pleaseCheck, type: 'error'})
        return false
      }
      if (!this.secondClick) {
        return false
      }
      this.secondClick = false
      this.axios({ // 发送银行卡账号数据
        method: 'post',
        url: this.$store.state.otcUrl.receiving.common,
        params: this.myData.bank,
        hostType: 'otc'
      }).then(res => {
        if (res.code.toString() === '0') {
          this.$router.go(0)
        } else {
          this.$store.dispatch('setTipState', {text: res.msg, type: 'error'})
        }
        this.secondClick = true
      }).catch(() => {
        this.secondClick = true
      })
    },
    setWechatBtn () {  // 确认
      if (this.userinfo.isOpenMobileCheck === 1 && this.userinfo.googleStatus !== 1) {
        this.myData.wechat.smsValidCode = this.formListWechat.smsValidCode.value
      } else if (this.userinfo.googleStatus === 1) {
        this.myData.wechat.googleCode = this.formListWechat.googleCode.value
      }
      for (let k in this.myData.wechat) {
        if (k === 'accountName' && this.myData.wechat[k] === null) { // 微信户名
          this.$store.dispatch('setTipState', {text: this.Internationalization.inputAccount, type: 'error'})
          return false
        }
        if (k === 'account' && this.myData.wechat[k] === null) { // 微信账号
          this.$store.dispatch('setTipState', {text: this.Internationalization.inputAccNumber, type: 'error'})
          return false
        }
        if (k === 'imgUrl' && this.myData.wechat[k] === null) { // 收款码
          this.$store.dispatch('setTipState', {text: this.Internationalization.pleaseUploadCollCode, type: 'error'})
          return false
        }
        if (k === 'smsValidCode' && this.userinfo.isOpenMobileCheck === 1 && this.userinfo.googleStatus !== 1) { // 短信验证码
          if (this.myData.wechat.smsValidCode.length !== 6) {
            this.$store.dispatch('setTipState', {text: this.Internationalization.VerificationNotRight, type: 'error'})
            return false
          }
        }
        if (k === 'googleCode' && this.userinfo.googleStatus === 1) {
          if (this.myData.wechat.googleCode.length !== 6) {
            this.$store.dispatch('setTipState', {text: this.Internationalization.VerificationNotRight, type: 'error'})
            return false
          }
        }
      }
      if (this.formData.wechatName.errorTip !== null) {
        this.$store.dispatch('setTipState', {text: this.Internationalization.pleaseCheck, type: 'error'})
        return false
      }
      if (!this.secondClick) {
        return false
      }
      this.secondClick = false
      this.axios({ // 发送微信账号数据
        method: 'post',
        url: this.$store.state.otcUrl.receiving.common,
        params: this.myData.wechat,
        hostType: 'otc'
      }).then(res => {
        if (res.code.toString() === '0') {
          this.$router.go(0)
        } else {
          this.$store.dispatch('setTipState', {text: res.msg, type: 'error'})
        }
        this.secondClick = true
      }).catch(() => {
        this.secondClick = true
      })
    },
    setAlipayBtn () {  // 确认
      if (this.userinfo.isOpenMobileCheck === 1 && this.userinfo.googleStatus !== 1) {
        this.myData.alipay.smsValidCode = this.formListAlipay.smsValidCode.value
      } else if (this.userinfo.googleStatus === 1) {
        this.myData.alipay.googleCode = this.formListAlipay.googleCode.value
      }
      for (let k in this.myData.alipay) {
        if (k === 'accountName' && this.myData.alipay[k] === null) { // 支付宝户名
          this.$store.dispatch('setTipState', {text: this.Internationalization.inputAccount, type: 'error'})
          return false
        }
        if (k === 'account' && this.myData.alipay[k] === null) { // 支付宝账号
          this.$store.dispatch('setTipState', {text: this.Internationalization.inputAccNumber, type: 'error'})
          return false
        }
        if (k === 'imgUrl' && this.myData.alipay[k] === null) { // 收款码
          this.$store.dispatch('setTipState', {text: this.Internationalization.pleaseUploadCollCode, type: 'error'})
          return false
        }
        if (k === 'smsValidCode' && this.userinfo.isOpenMobileCheck === 1 && this.userinfo.googleStatus !== 1) { // 短信验证码
          if (this.myData.alipay.smsValidCode.length !== 6) {
            this.$store.dispatch('setTipState', {text: this.Internationalization.VerificationNotRight, type: 'error'})
            return false
          }
        }
        if (k === 'googleCode' && this.userinfo.googleStatus === 1) {
          if (this.myData.alipay.googleCode.length !== 6) {
            this.$store.dispatch('setTipState', {text: this.Internationalization.VerificationNotRight, type: 'error'})
            return false
          }
        }
      }
      if (this.formData.aplayName.errorTip !== null) {
        this.$store.dispatch('setTipState', {text: this.Internationalization.pleaseCheck, type: 'error'})
        return false
      }
      if (!this.secondClick) {
        return false
      }
      this.secondClick = false
      this.axios({ // 发送阿里账号数据
        method: 'post',
        url: this.$store.state.otcUrl.receiving.common,
        params: this.myData.alipay,
        hostType: 'otc'
      }).then(res => {
        if (res.code.toString() === '0') {
          this.$router.go(0)
        } else {
          this.$store.dispatch('setTipState', {text: res.msg, type: 'error'})
        }
        this.secondClick = true
      }).catch(() => {
        this.secondClick = true
      })
    },
    wechatImgUrl (msg) {
      this.myData.wechat.imgUrl = msg.value.base_image_url + msg.value.filename
      this.wechatShowImg = this.myData.wechat.imgUrl ? this.myData.wechat.imgUrl : null
    },
    alipayImgUrl (msg) {
      this.myData.alipay.imgUrl = msg.value.base_image_url + msg.value.filename
      this.alipayShowImg = this.myData.alipay.imgUrl ? this.myData.alipay.imgUrl : null
    },
    goBack () {
      this.defaultPage = true
      this.alipayPage = false
      this.wechatPage = false
      this.bankPage = false
    },
    // 收付款设置按钮
    toPayAndCollSet (method) {
      if (this.userinfo.googleStatus === 0 && this.userinfo.isOpenMobileCheck === 0) {
        this.googleOrMobelVerty = true
        return false
      }
      if (this.userinfo.authNewLevel === 'C0') {
        this.toC1Verify = true
        return false
      }
      switch (method) {
        case 'alipay':
          this.defaultPage = false
          this.alipayPage = true
          break
        case 'wechat':
          this.defaultPage = false
          this.wechatPage = true
          break
        case 'bank':
          this.defaultPage = false
          this.bankPage = true
          break
      }
    },
    // 关闭弹窗
    closeDialog () {
      this.toC1Verify = false
      this.googleOrMobelVerty = false
    }
  },
  mounted () {
    let bool = this.userinfo.googleStatus !== 0 || this.userinfo.isOpenMobileCheck !== 0
    this.userinfo && this.userinfo.authNewLevel !== 'C0' && bool && this.paymentsData()
  },
  watch: {
    'userinfo' (val) {
      this.formListBank = this._P.copyObject(this.formList_obj, true)
      this.formListWechat = this._P.copyObject(this.formList_obj, true)
      this.formListAlipay = this._P.copyObject(this.formList_obj, true)
      let bool = val.googleStatus !== 0 || val.isOpenMobileCheck !== 0
      val && val.authNewLevel !== 'C0' && bool && this.paymentsData()
    },
    'formList_obj' (val) {
      this.formListBank = this._P.copyObject(val, true)
      this.formListWechat = this._P.copyObject(val, true)
      this.formListAlipay = this._P.copyObject(val, true)
    },
    'formData_obj' (val) {
      this.formData = val
    }
  }
}
</script>
